package com.ferry.wallpaper.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ferry.wallpaper.mapper.WallMapper;
import com.ferry.wallpaper.domain.Wall;
import com.ferry.wallpaper.service.WallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WallServiceImpl implements WallService {

    @Autowired
    private WallMapper wallMapper;

    @Override
    public List<Wall> getPage(String typeName, Integer size, Integer page) {
        Page<Wall> pg = new Page<Wall>(page,size);
        QueryWrapper<Wall> wrapper = new QueryWrapper<Wall>();
        if (typeName == null) {
            wrapper = wrapper.orderByAsc("WALL_SORT");
        } else {
            wrapper = wrapper.eq("WALL_TYPE_NAME",typeName).orderByAsc("WALL_SORT");
        }
        pg = wallMapper.selectPage(pg, wrapper);
        return pg.getRecords();
    }

    @Override
    public Wall get(Long id) {
        return wallMapper.selectById(id);
    }
}
